package com.util;

/**
 * User: asan
 * Date: 2014/10/29
 * Time: 14:18
 */
public class RandomStringGenerator {

    /**
     * 获取一定长度的随机字符串
     * @param length 指定字符串长度
     * @return 一定长度的字符串
     */
    public static String getRandomStringByLength(int length) {
        String fourRandom = "";
        // 产生n位的随机数(不足前加零)
        int randomNum = (int) (Math.random() * 1000000);
        fourRandom = randomNum + "";
        int randLength = fourRandom.length();
        if (randLength < length) {
            for (int i = 1; i <= length - randLength; i++)
                fourRandom = fourRandom + "0";
        }
       return   fourRandom;
    }

}
